﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Electro;
using Circuit;
using UI;

namespace Electricity
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }
        int sumV = 0;
        Electronics circuit = Factory.CreateCircuit();
        private void button1_Click(object sender, EventArgs e)
        {
            
            
            for (int i = 0; i < checkedListBox1.CheckedIndices.Count; i++)
            {
                circuit.addDevice(Factory.CreateElectronics(checkedListBox1.CheckedIndices[i]));
            }
            
            for (int i = 0; i < checkedListBox1.CheckedItems.Count; i++)
            {
                listBox1.Items.Add(checkedListBox1.CheckedItems[i]);
            }

            sumV = circuit.calculateSumVoltage();
            
            label3.Text = sumV.ToString();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Разработал: Бокарев Борис, группа 8В13 \n Версия 1.0", "О программе", MessageBoxButtons.OK);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            
                if (sumV != 0)
                {
                    circuit.removeDevice(listBox1.SelectedIndex);
                    listBox1.Items.Remove(listBox1.SelectedItem);
                    sumV = circuit.calculateSumVoltage();

                    label3.Text = sumV.ToString();
                }
                   
         }
            
        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }
    }
}
